package com.demo.common.kit;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

public class ExportKit {

	/**
	 * 
	 * @param headersInfo 表头
	 * @param sheet sheet
	 * @param rowNum 生成表头的行数
	 */
	public static void outputHeaders(String[] headersInfo, HSSFSheet sheet, Integer rowNum) {
		HSSFRow row;
		if(rowNum == null)
			row = sheet.createRow(0);
		else 
			row = sheet.createRow(rowNum);
		for (int i = 0; i < headersInfo.length; i++) {
			sheet.setColumnWidth(i, 4000);
			row.createCell(i).setCellValue(headersInfo[i]);
		}
	}
	
	/**
	 * 
	 * @param headersInfo
	 * @param sheet
	 * @param startRowNum
	 */
	public static void outputColumns(String[] headersInfo,List<? extends Object> columnList, HSSFSheet sheet, Integer startRowNum) {
		HSSFRow row;
		for (int i = 0; i < columnList.size(); i++) {
			row = sheet.createRow(startRowNum + i);
			Object obj = columnList.get(i);
			for (int j = 0; j < headersInfo.length; j++) {
				Object value = getFieldValueByName(headersInfo[j], obj);
				row.createCell(j).setCellValue(value.toString());
			}
		}
	}

	private static Object getFieldValueByName(String fieldName, Object obj) {
		
		return null;
	}
}
